<template>
	<view class="bgfff">
		<view class="top pl25 pr25 pt15 pb15 ft12">
			多位认证医生提供健康建议，10分钟内快速回复，已累计帮主患者解决100万个健康问题，好评率99%
		</view>
		<view class="pl25 pr25">
			<input class="bb" @input="setConditioninfo" maxlength="25" placeholder="请一句话概述您的病况（不超过25字）" />
			<textarea class="c666 mt30 mb30 pb30" @input="setProblem" placeholder="请详细描述病症，发病时间、部位以及目前的用药情况，我们将按照您的描述向对应科室的2位医  生进行留言，提交后请耐心等待"></textarea>
			<view class="pt30">上传相关图片（检查报告、患处照片等）</view>
		</view>
		<view class="imgs pl10 pr10">
			<block v-for="(item,index) in Imgs" :key="index">
				<image :src="item"></image>
			</block>
			<image src="http://tuozhen1.oss-cn-beijing.aliyuncs.com/ueditor/upload/weixin/images/upimg.png" @click="uploadImg"></image>
		</view>
		<view class="bottomBtn ftc">
			<view class="bottomBtncon bgfff">
				<text class="cfff btns ct ftc block" @click="addMedFreeOrd">提交问题</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				usrUserId:null,
				wx: "https://app.mzmzb.com",//https://app.mzmzb.com   http://localhost:6110
				Imgs:[],
				conditioninfo:'',//病况
				problem:'',//病情详细描述
			};
		},
		onLoad(option) {
			this.usrUserId=option.usrUserId;
		},
		onShow() {
			
		},
		methods: {
			// uploadImg(){
			// 	let _this = this;
			// 	uni.chooseImage({
			// 	  count: 9, //图片个数
			// 	  sizeType: ['original'],
			// 	  sourceType: ['album', 'camera'],
			// 	  success (res) {
			// 		_this.Imgs = [..._this.Imgs,...res.tempFilePaths]
			// 		console.log(_this.Imgs)
			// 		uni.uploadFile({
			// 			url:''
			// 		})
			// 	  }
			// 	})
			// }
			//上传图片到oss
			uploadImg() {
			    var that = this
			    uni.chooseImage({
			      count: 9, // 默认9
			      sizeType: ['original','camera'], // 可以指定是原图还是压缩图，默认二者都有
			      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			      success: function (res) {
					  uni.showLoading({
					  		title: '上传中...'
					  });
			        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
			        var tempFilePaths = res.tempFilePaths
			        var myDate = new Date()
			        var ossPath = 'ueditor/upload/weixin/' + myDate.getFullYear()
					var fileKeylist=[]
					
			        for (var i = 0; i < tempFilePaths.length; i++) {
			          // 获取文件后缀
			          //var pathArr = tempFilePaths[i].split('.')
					  const imgsrc = res.tempFilePaths[i];
					  const index = imgsrc.lastIndexOf(".");
					  const imgExtension = imgsrc.substring(index + 1, imgsrc.length);
					  console.log("后缀："+imgExtension)
			          //  随机生成文件名称
			          var fileRandName = Date.now() + "" + parseInt(Math.random() * 1000)
			          var fileName = fileRandName + '.'+imgExtension
			          // 要提交的key
			          var fileKey = ossPath + '/' + fileName
					  fileKeylist.push(fileKey)
			          uni.uploadFile({
			            url: 'https://tuozhen1.oss-cn-beijing.aliyuncs.com/', 
			            filePath: tempFilePaths[i],
			            name: 'file',
			            formData: {
			              name: tempFilePaths[i],
			              key: fileKey,
			              policy: 'eyJleHBpcmF0aW9uIjoiMjMzNy0wNC0xM1QwMjo0MjoxMi40ODFaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF0sWyJzdGFydHMtd2l0aCIsIiRrZXkiLCJ1ZWRpdG9yL3VwbG9hZC93ZWl4aW4vIl1dfQ==',
			              OSSAccessKeyId: 'Te5npXFe8IdIxPgQ',
			              signature: 'I1Dv3FioQ4hoBh0ui2Rvsax+fAI=',
			              success_action_status: "200"
			            },
			            success: function (res) {
			              console.log(res)
			            }
			          })
			        }
					
					setTimeout(function () {
					           that.getImgs(fileKeylist);
					        }, 5000);
			      }
			    })
			  },
			  getImgs(e)
			  {
				  var that=this; 
				  for(var i=0;i<e.length;i++){
					 var upliadImages="http://tuozhen1.oss-cn-beijing.aliyuncs.com/"+e[i];
					 console.log("携带的参数："+upliadImages)
					 that.Imgs.push(upliadImages);
				  }
				  uni.hideLoading();
			  },
			  //这是病况的值
			  setConditioninfo(e){
				  this.conditioninfo = e.detail.value
				  console.log(this.conditioninfo)
			  },
			  //设置病情描述的值
			  setProblem(e){
				 this.problem = e.detail.value
				 console.log(this.problem) 
			  },
			  //提交免费咨询
			 addMedFreeOrd(){
			 			  uni.showLoading({
			 			  	title: '提交中...'
			 			  });
			 			  var that=this;
			 			  var images=that.Imgs;
			 			  console.log("图片:"+images)
			 			 console.log("参数:"+that.conditioninfo)
			 			  console.log("参数:"+that.problem)
			 			  let data={
			 				  usrUserId:thst.usrUserId,
			 				  conditioninfo:thst.conditioninfo,
			 				  problem:that.problem,
			 				  image:images
			 				  
			 			  }
			 			  that.func.$request('wx/addMedFreeOrd.tz',data,'POST').then(res=>{
			 				  if(res.data.result!=null){
			 				  	console.log(res.data)
			 				  		uni.showToast({
			 				  			title:'提交成功',
			 				  			duration:1000
			 				  		}),
			 				  		setTimeout(function () {
			 				  		           uni.navigateBack();
			 				  		        }, 1000);
			 				  }
			 			  })
			 		  },
			 	}
			 };
</script>

<style lang="less">
	page{
		background: #EFEFEF;
	}
	.top {
		background: #fdf0cb;
		color: #fec322;
		line-height: 45rpx;
	}
	input{
		height: 105rpx;
		line-height: 105rpx;
	}
	.imgs{
		image{
			width: 120rpx;
			height: 97rpx;
			margin: 10rpx;
		}
	}
	.bottomBtn{
		position: relative;
		height: 125rpx;
		width: 100%;
		.bottomBtncon{
			position: fixed;
			width: 100%;
			z-index: 10;
			left: 0;
			height: 125rpx;
			bottom: 0;
			.btns{
				width: 660rpx;
				height: 100rpx;
				line-height: 100rpx;
				border-radius: 10rpx;
				background: #74a6fd;
			}
		}
	}
</style>
